<template>
  <div class="message">
    <Breadcrumb :pathContent="content" />
    <!-- <el-form>
            <el-form-item>
                <div class="message-content">
                    <el-tabs v-model="activeName">
                        <el-tab-pane label="业务消息" name="first"><MessageList/></el-tab-pane>
                    </el-tabs>
                    <div class="all-read">
                        <el-button type="text" @click="allRead">全部标记为已读</el-button>
                    </div>
                </div>
            </el-form-item>
        </el-form> -->
    <el-form :inline="true">
      <el-form-item>
        <el-dropdown @command="setState">
          <span class="el-dropdown-link">
            {{stateTitle}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{ 'key' : 'state', value: '', title: '全部消息'}">全部消息</el-dropdown-item>
            <el-dropdown-item :command="{ 'key' : 'state', value: '0', title: '订单通知'}">订单通知</el-dropdown-item>
            <el-dropdown-item :command="{ 'key' : 'state', value: '1', title: 'MINI消费'}">MINI消费</el-dropdown-item>
            <el-dropdown-item :command="{ 'key' : 'state', value: '2', title: '退房通知'}">退房通知</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>

      <el-form-item>
        <el-dropdown @command="seTimeType">
          <span class="el-dropdown-link">
            {{timeTypStr}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{title:'创建时间',id:'1'}">创建时间</el-dropdown-item>
            <el-dropdown-item :command="{title:'处理时间',id:'2'}">处理时间</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
      <el-form-item style="margin-right:20px">
        <el-date-picker v-model="startEndTime"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :disabled="isDisable"
          clearable
          :editable="false"
          @change="timeSearch">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="请输入订单编号"
          v-model="sendData.num"
          clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="请输入订单标题"
          v-model="sendData.search"
          clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          style=" line-height: 32px;padding: 0 21px;"
          @click="handleSearch"></el-button>
      </el-form-item>
      <el-form-item style="float:right">
        <div class="all-read">
          <el-button type="text"
            @click="allRead">全部标记为已读</el-button>
        </div>
      </el-form-item>

      <div class="message-list">
        <div class="warpper">
          <div class="list-content"
            v-for="(item,index) in tableData"
            :key="index">
            <div class="content">
              <div class="content-left">
                <div class="title">
                  <label :class="{'font-style': item.handler !== null}"
                    style="width:120px;display: inline-block;">{{item.type}}&nbsp&nbsp&nbsp&nbsp&nbsp</label>
                  <label :class="{'font-style': item.handler !== null}">{{item.createTime}}&nbsp&nbsp&nbsp&nbsp&nbsp</label>
                  <label :class="{'font-style': item.handler !== null}">{{item.num}}</label>
                </div>
                <div class="content-text">
                  <label :class="{'font-style': item.handler !== null}">{{item.title}}</label>
                </div>
              </div>
              <div class="content-right">
                <div class="deal-content">
                  <el-button type="text"
                    @click="messageState(item)"
                    v-if="item.handler === null">未读查看</el-button>
                  <label :class="{'font-style': item.handler !== null}"
                    v-if="item.handler !== null">已读</label>
                  <!-- &nbsp&nbsp&nbsp&nbsp&nbsp<label :class="{'font-style': item.handler !== null}">{{item.handler}}</label> -->
                  <label :class="{'font-style': item.handler !== null}"
                    v-if="item.handler !== null">{{item.handlingTime}}</label>
                </div>
                <div class="time"></div>
              </div>
            </div>
          </div>
        </div>
        <el-form-item style="margin-top: 20px;float:right">
          <el-pagination @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, prev , pager , next, sizes, jumper"
            :total="total">
          </el-pagination>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
import {
  setMessageState,
  getMessageList,
  messageCount,
  clearMessageAll
} from "../../public/js/message";
const Breadcrumb = () => import("@/components/common/Breadcrumb");
const MessageList = () => import("@/components/message/MessageList");

export default {
  name: "Staff",
  token: "",
  data() {
    return {
      activeName: "first",
      information: {},
      content: {
        firstTitle: "消息",
        secondTitle: "消息列表",
        type: "close"
      },
      resdData: [],
      // sendData: {
      //   pageSize: 10,
      //   pageNum: 1
      // },
      sendData: {
        pageNo: 1,
        pageSize: 10,
        search: "",
        type: "",
        timeType: "",
        startTime: "",
        endTime: "",
        num: ""
      },
      total: 0,
      tableData: [],
      ids: [],
      pageNo: 1,
      pageSize: 10,
      stateTitle: "全部消息",
      search: "",
      timeTypStr: "全部日期",
      isDisable: true,
      startEndTime: [],
      type: ""
    };
  },
  created() {
    this.getMessageLists();
  },
  mounted() {},
  methods: {
    dataReset(res, data) {
      this.resdData = [];
      res.forEach(item => {
        if (item.handler === null) this.resdData.push(item.id);
      });
      this.sendData.pageSize = data.pageSize;
      this.sendData.pageNo = data.pageNo;
    },
    //全部清空
    allRead() {
      clearMessageAll().then(res => {
        if (!res.data.errCode) {
          this.$message.success("当前页面已全部标为已读");
          window.bus.$emit("messageCount", 0);
          this.getMessageLists();
        }
      });
    },
    //获取消息列表
    getMessageLists() {
      getMessageList(this.sendData).then(res => {
        this.tableData = res.data.messageEntities;
        this.total = res.data.total;
      });
    },
    //消息处理
    messageState(val) {
      this.ids = [];
      this.ids.push(val.id);
      setMessageState(this.sendData, this.ids).then(res => {
        if (res.data.errCode === 0) {
          this.$message.success("处理成功");
          this.tableData = res.data.messageEntities;
          if (val.typeI == 0) {
            this.$router.push("/index/order_detail?id=" + val.omcId);
          }
          if (val.typeI == 1) {
            this.$router.push("/index/list_goods_detail?id=" + val.omcId);
          }
          if (val.typeI == 2) {
            this.$router.push("/index/checkIn-detail?id=" + val.omcId);
          }
          messageCount().then(res => {
            if (res.data.errCode === 0)
              window.bus.$emit("messageCount", res.data.count);
          });
        }
      });
    },
    //全部状态
    setState(data) {
      this.stateTitle = data.title;
      this.sendData.type = data.value;
      this.pageSize = 10;
      this.pageNo = 1;
      this.getMessageLists();
    },
    // 时间类型选择
    seTimeType(command) {
      this.sendData.timeType = command.id;
      this.timeTypStr = command.title;
      console.log(command);
      if (!this.sendData.timeType) {
        this.isDisable = true;
      } else {
        this.isDisable = false;
      }
    },
    // 根据时间查询
    timeSearch(val) {
      this.sendData.startTime = val ? val[0] : "";
      this.sendData.endTime = val ? val[1] : "";
      this.sendData.pageNo = 1;
      this.sendData.pageSize = 10;
      //this._getNoticeList();
    },
    //查询
    handleSearch() {
      this.sendData.pageSize = 10;
      this.sendData.pageNo = 1;
      this.getMessageLists();
    },
    handleSizeChange(val) {
      this.sendData.pageSize = val;
      this.getMessageLists();
    },
    handleCurrentChange(val) {
      this.sendData.pageNo = val;
      this.getMessageLists();
    }
  },
  components: {
    Breadcrumb
    //MessageList
  }
};
</script>
<style lang="scss">
.message {
  #tab-first {
    margin-bottom: 30px;
  }
  .message-content {
    margin-top: 20px;
    background-color: white;
    padding: 20px 30px;
    position: relative;
    .all-read {
      position: absolute;
      top: 2%;
      right: 1.8%;
    }
  }

  .el-form {
    padding: 30px 20px;
  }
  .message-list {
    .warpper {
      max-height: 550px;
      overflow: auto;
      .list-content {
        border-bottom: 1px solid #cdd9e6;
        .content {
          overflow: hidden;
          padding: 10px 20px;
        }
        .content-left,
        .content-right {
          float: left;
          line-height: 2;
          label,
          button {
            font-size: 12px;
          }
        }
        .content-left {
          width: 60%;
          .title,
          .content-text {
            float: left;
            width: 40%;
          }
          .title {
            width: 60%;
          }
          text-align: left;
        }
        .content-right {
          width: 40%;
          text-align: right;
          .deal-content {
          }
        }
      }
    }
    .font-style {
      color: rgb(182, 192, 201);
    }
  }
}
</style>
